package com.spring.springmvc.用户登录;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StreamUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

@RequestMapping("user")
@RestController
public class login {
    @RequestMapping("login")
    public Boolean login(String username, String password, HttpSession session){
        //判断是否输入数据
        if(!StringUtils.hasLength(username)||!StringUtils.hasLength(password)){
            return false;
        }
        //判断输入的数据是否正确(判断数据是不是张三)
        if("zhangsan".equals(username)&&"123".equals(password)){
            //“username”不是值，而是名称，后面的username是值
            session.setAttribute("name",username);
            return true;
        }
        return false;
    }

    @RequestMapping("index")
    //获取session
    public String getName(@SessionAttribute("name") String name){
        return name;
    }
}
